import { NodeStatus } from "../NodeStatus";
import { DecoratorNode } from "./DecoratorNode";


/**
 * 如果子节点执行后返回RUNNING，该节点返回RUNNING；否则，该节点返回FAILURE，即强制返回失败状态。
 */
export class ForceFailureNode<T> extends DecoratorNode<T> {

    constructor(name: string, blackboard: T) {
        super(name, blackboard);
    }

    Tick(): NodeStatus {
        this.status = NodeStatus.RUNNING;

        const child_state = this.GetChild()!.Evaluate();

        switch (child_state) {
            case NodeStatus.FAILURE:
            case NodeStatus.SUCCESS: {
                return NodeStatus.FAILURE;
            }
            case NodeStatus.RUNNING: {
                return NodeStatus.RUNNING;
            }
        }
        return this.status;
    }
}